# -*- coding: utf-8 -*-
"""
Created on Sat Mar 27 17:33:22 2021

@author: Apple
"""


import sys
from PyQt5.QtWidgets import (QWidget,QTableWidget,QHBoxLayout,QApplication,QTableWidgetItem)

class Table(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.setWindowTitle('QTableWidget例子')
        self.resize(400,300)
        conLayout = QHBoxLayout()
        tableWidget = QTableWidget()
        tableWidget.setRowCount(4) # 设置行数
        tableWidget.setColumnCount(3) # 设置列数
        conLayout.addWidget(tableWidget)
        tableWidget.setHorizontalHeaderLabels(['姓名','性别','体重']) #设置表头
        
        newItem = QTableWidgetItem('张三')
        tableWidget.setItem(0,0,newItem)
        
        newItem = QTableWidgetItem('男')
        tableWidget.setItem(0,1,newItem)      

        newItem = QTableWidgetItem('160')
        tableWidget.setItem(0,2,newItem)
        
        self.setLayout(conLayout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    example= Table()
    example.show()
    sys.exit(app.exec_())
    

        